/* 
 * File:   main.cpp
 * Author: Potential
 *
 * Created on August 31, 2013, 5:02 PM
 */

#include <cstdlib>
#include <stdlib.h>
#include <stdio.h>
#include <string>
#include <iostream>
#include <windows.h>
#include "Hero.h"
#include "Enemy.h"

using namespace std;

Hero hero;
Enemy enemy;

/*
 * 
 */

void encounter(int enemyNum)
{
    if (enemyNum == 1)
    {
        cout << "===========================" << endl;
        cout << "=     First Encounter     =" << endl;
        cout << "===========================" << endl;
    }
    else if (enemyNum == 2)
    {
        cout << "===========================" << endl;
        cout << "=    Second Encounter     =" << endl;
        cout << "===========================" << endl;
    }
    else if (enemyNum == 3)
    {
        cout << "===========================" << endl;
        cout << "=     Final Encounter     =" << endl;
        cout << "===========================" << endl;
    }
}

void heroAttackPrompt()
{
    string pause;
    cout << "Press A and then enter to attack...";
    cin >> pause;
    cout << endl;
    
    int heroDamage = 0;
    
    heroDamage = hero.getDamage() - enemy.getArmor();

    cout << hero.getName() << " attacks " << enemy.getName() << " for " << heroDamage
            << " damage." << endl << endl;
    
    enemy.setCurHealth(enemy.getCurHealth() - heroDamage);
    
    Sleep(2000);
}

void enemyAttack()
{
    int enemyDamage = 0;
    
    enemyDamage = enemy.getDamage() - hero.getArmor();
    cout << enemy.getName() << " attacks " << hero.getName() << " for " << enemyDamage
            << " damage." << endl << endl;
    
    hero.setCurHealth(hero.getCurHealth() - enemyDamage);
    
    Sleep(2000);
}

void enemyDefeat()
{
    cout << enemy.getName() << " has been defeated." << endl << endl;
}

int main(int argc, char** argv) 
{    
    int enemyNum = 1;
    
    bool heroDefeated = false;
    bool enemyDefeated = false;
    
    string heroName = "";
    
    //Welcome banner
    cout << "Welcome to Text RPG!!!\n";
    hero.setName();
    hero.difficultySelection();
    
    Sleep(2000);
    system ("cmd.exe /c cls");
    
    while (heroDefeated == false && enemyNum <= 4)
    {
        enemy.enemySelection(enemyNum);
        
//        if (enemyNum == 1)
//        {
            encounter(enemyNum);
            
            while (heroDefeated == false && enemyDefeated == false)
            {
                hero.displayStats();
                enemy.displayStats();
                heroAttackPrompt();

                if (enemy.getCurHealth() > 0)
                {
                    hero.displayStats();
                    enemy.displayStats();
                    enemyAttack();
                }
                else
                {
                    enemyDefeated = true;
                    enemyDefeat();
                }

                if (hero.getCurHealth() <= 0)
                {
                    heroDefeated = true;
                }
            }

        if (enemyNum == 4 && heroDefeated == false)
        {
            //Victory banner
            cout << "===== VICTORY!!! =====" << endl;
        }
        
        enemyNum++;
        enemyDefeated = false;
        hero.resetHealth();
    }
    
    if (heroDefeated == true)
    {
        //Defeat banner
        cout << "===== DEFEAT!!! =====" << endl;
    }
    
    return 0;
}

